USE Liberty
GO

-- ------------------------------------------------------------------------------------------------
-- CaseAssignments Table Create Script
-- ------------------------------------------------------------------------------------------------
SET NOCOUNT OFF
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
GO

PRINT 'Creating Table dbo.CaseAssignments...'
GO

IF OBJECT_ID('dbo.CaseAssignments', 'U') IS NULL
BEGIN
	CREATE TABLE dbo.CaseAssignments
	(OID				bigint		IDENTITY(1, 1)	NOT NULL
	,Version			rowversion
	,CaseID				bigint						NOT NULL
	,UserID				bigint						NOT NULL
	,StartDate			datetime						NULL
	,EndDate			datetime						NULL

	,UpdatedDate		datetime					NOT NULL
		CONSTRAINT DFLT_CaseAssignments_UpdatedDate DEFAULT GETDATE()
	,CreatedDate		datetime					NOT NULL
		CONSTRAINT DFLT_CaseAssignments_CreatedDate DEFAULT GETDATE()

	,CONSTRAINT PK_CaseAssignments PRIMARY KEY CLUSTERED( OID ) --ON PRIMARY

	,CONSTRAINT FK_CaseAssignments_Cases FOREIGN KEY (CaseID)
		REFERENCES Cases(OID)

	,CONSTRAINT FK_CaseAssignments_Users FOREIGN KEY (UserID)
		REFERENCES Users(OID)

	)

	PRINT 'Table dbo.CaseAssignments has been created successfully.'

END
ELSE 
BEGIN
    PRINT 'Table dbo.CaseAssignments already exists.'
END

GO
